package com.xiaoxi.exam.service;

import com.xiaoxi.exam.dao.BoughtRecordMapper;
import com.xiaoxi.exam.model.BoughtRecord;
import com.xiaoxi.exam.model.BoughtRecordExample;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BoughtRecordService {

  @Autowired
  private BoughtRecordMapper boughtRecordMapper;

  public void addBoughtRecord(BoughtRecord boughtRecord) {
    boughtRecordMapper.insert(boughtRecord);
  }

  public long countByOrderId(Long id) {
    BoughtRecordExample example = new BoughtRecordExample();
    example.or().andOrderIdEqualTo(id).andDeletedAtIsNull();
    return boughtRecordMapper.countByExample(example);
  }

  public List<BoughtRecord> getByOrderId(Long id, int pageAt, int pageSize) {
    BoughtRecordExample example = new BoughtRecordExample();
    example.or().andOrderIdEqualTo(id).andDeletedAtIsNull();
    example.setLimit(pageSize);
    example.setOffset(pageAt * pageSize);
    return boughtRecordMapper.selectByExample(example);
  }
}
